import datetime
import time

import jwt

from mypro.settings import SECRET_KEY

key = SECRET_KEY


class MyJWT():
    def getToken(self, user_id,user_name):
        user={
            "id":user_id,
            "username":user_name,
            'exp':time.time() + 3600 * 3
        }
        return "Bearer " + jwt.encode(user, key, algorithm="HS256")

    def regetToken(self, user_id, user_name):
        user = {
            "id": user_id,
            "username": user_name,
            'exp': time.time() + 3600 * 4
        }
        return "Bearer " + jwt.encode(user, key, algorithm="HS256")

    def Checktoken(self, token):
        if token:
            return jwt.decode(token, key, algorithms=['HS256'])


myjwt = MyJWT()
